import Vue from 'vue'
import Router from 'vue-router'

const Home = () => import('views/home/Home')
const Category = () => import('views/category/Category')
const Cart = () => import('views/cart/Cart')
const Profile = () => import('views/profile/Profile')
const Detail = () => import('views/detail/Detail')
Vue.use(Router)
//replace
// 解决router再次点击报错问题
const VueRouterReplace = Router.prototype.replace
Router.prototype.replace = function replace(to) {
  return VueRouterReplace.call(this, to).catch(err => err)
}
// push
const originalPush = Router.prototype.push;
Router.prototype.push = function push(to) {
  return originalPush.call(this, to).catch(err => err);
};

const routes = [{
    path: '',
    redirect: '/home'
  },
  {
    path: '/home',
    name: "home",
    component: Home
  },
  {
    path: '/category',
    name: "category",
    component: Category
  },
  {
    path: '/cart',
    name: "cart",
    component: Cart
  },
  {
    path: '/profile',
    name: "profile",
    component: Profile
  },
  {
    path: '/detail:iid',
    name: "detail",
    component: Detail
  },
  {
    path: "*",
    redirect: "/"
  }
]

const router = new Router({
  routes,
  mode: 'hash',
  base: process.env.NODE_ENV === "production" ? "/shop" : "/",

})

export default router